package com.example.data.factory.web1.controller;

import com.example.data.factory.common.Dto.*;
import com.example.data.factory.common.result.R;
import com.example.data.factory.entity.entity.Script;
import com.example.data.factory.service.service.ScriptService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lhy
 * @since 2025-03-03
 */
@RestController
@RequestMapping("/script")
public class ScriptController {
    @Resource
    private ScriptService scriptService;

    @GetMapping("/SearchScript")
    public R<Script> SearchScript(SearchScriptDto searchScriptDto) {
        return scriptService.search ( searchScriptDto );
    }

    @PostMapping(value = "/InsertScript", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<Script> InsertScript(
            @ModelAttribute @Valid InsertScriptDto insertScriptDto,
            HttpServletRequest request,
            @RequestParam("file") MultipartFile file) {
        return scriptService.insert ( insertScriptDto, request, file );
    }

    @PutMapping("/UpdateScriptStatus")
    public R<Script> UpdateScriptStatus(@RequestBody UpdateScriptStatusDto updateScriptStatusDto) {
        return scriptService.updatestatus ( updateScriptStatusDto );
    }

    @PutMapping("/UpdateScriptStatusBash")
    public R<Script> UpdateScriptStatusBash(@RequestBody List<UpdateScriptStatusDto> updateScriptStatusDtos) {
        return scriptService.updatestatusbash ( updateScriptStatusDtos );
    }

    @DeleteMapping("/DeletScript")
    public R<Script> DeletScript(@RequestBody DeleteScriptDto deleteScriptDto) {
        return scriptService.delete ( deleteScriptDto );
    }

    @GetMapping("/SearchScriptById")
    public R<Script> SearchScriptById(DeleteScriptDto deleteScriptDto) {
        return scriptService.searchbyid ( deleteScriptDto );
    }

    @PutMapping("/UpdateScript")
    public R<Script> UpdateScript(@Valid UpdateScriptDto updateScriptDto, @RequestParam(value = "file", required = false) MultipartFile file) {
        return scriptService.updates ( updateScriptDto, file );
    }

    @PostMapping("ClassifyBatch")
    private R<Map<String, String>> ClassifyBatch(@RequestBody ScriptClassifyBatch scriptClassifyBatch) {
        return scriptService.updatesBatch ( scriptClassifyBatch );
    }

    @PostMapping("/test/{scriptId}")
    public R<String> testScript(@PathVariable Integer scriptId, @RequestBody String inputData) {
        return scriptService.testScriptById ( scriptId, inputData );
    }

    @PostMapping("test")
    public Map<String, String> testInterfaces(Integer scriptId) {
        return scriptService.testInterfaces ( scriptId );
    }

    ;
}


